import axios from "axios";
import { ElMessage } from "element-plus";
import router from '../router/index'

const instance = axios.create({
    baseURL: 'http://82.156.12.132:8080/api/private/v1',
    timeout: 6000
})

instance.interceptors.request.use(
    (config) => {
        config.headers.Authorization = window.localStorage.getItem('token')
        return config
    },
    (error) => {
        return error
    }
)
instance.interceptors.response.use((res) => {
     if(res.data.meta.status==400){
        ElMessage({
            showClose: true,
            message: 'token过期,请先登录',
            type: "error",
          });
          router.push('/login')
     }
    return res
},
    (error) => {
        console.log(456);
        return error
    }
)

export default instance
